package com.rr.middle;

/**
 * @author RR
 * @date 2024/7/14 19:51
 */
public class MaximumPrimeDifference {
    public int maximumPrimeDifference(int[] nums) {
        int start = 0;
        int end = 0;
        int length = nums.length;
        for (int i = 0; i < length; i++) {
            if (isPrime(nums[i])) {
                start = i;
                break;
            }
        }
        for (int i = length - 1; i >= 0; i--) {
            if (isPrime(nums[i])) {
                end = i;
                break;
            }
        }
        return end - start;
    }

    private boolean isPrime(int num) {
        if (num == 1) {
            return false;
        }
        int tmp = 2;
        while (tmp < num) {
            if (num % tmp == 0) {
                return false;
            }
            tmp++;
        }
        return true;
    }
}
